//
//  HSQBtnListCollectionViewCell.m
//  LiTianDecoration
//
//  Created by administrator on 2018/7/31.
//  Copyright © 2018年 administrator. All rights reserved.
//

#import "HSQBtnListCollectionViewCell.h"
#import "HSQFilterCategoryListModel.h"

@interface HSQBtnListCollectionViewCell ()

@property (nonatomic, strong) UIButton *screening_btn;

@end

@implementation HSQBtnListCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        // 筛选按钮
        UIButton *screening_btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        screening_btn.titleLabel.font = [UIFont systemFontOfSize:13.0];
        [screening_btn setTitleColor:RGB(71, 71, 71) forState:(UIControlStateNormal)];
        [screening_btn setTitleColor:RGB(238, 58, 68) forState:(UIControlStateSelected)];
        [screening_btn setBackgroundImage:[UIImage ImageWithColor:RGB(241, 241, 246)] forState:(UIControlStateNormal)];
        [screening_btn setBackgroundImage:[UIImage ImageWithColor:RGB(255, 255, 255)] forState:(UIControlStateSelected)];
        [screening_btn setImage:KImageName(@"btn_check") forState:(UIControlStateSelected)];
        [screening_btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
        [screening_btn addTarget:self action:@selector(screening_btnClickAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:screening_btn];
        self.screening_btn = screening_btn;
        
        // 添加约束
        self.screening_btn.sd_layout.leftSpaceToView(self.contentView, 10).centerYEqualToView(self.contentView).heightIs(30).widthIs((KScreenWidth - 40) / 3 - 15);
        [self.screening_btn setSd_cornerRadius:@(5)];
        
    }
    
    return self;
}

/**
 * @brief 提示文字
 */
- (void)setModel:(HSQFilterAttributeListModel *)model{
    
    _model = model;
    
    if (model.IsSelect_State.integerValue == 0) // 默认状态
    {
         [self.screening_btn setTitle:model.attributeName forState:(UIControlStateNormal)];
        
        [self.screening_btn setSelected:NO];
        
        self.screening_btn.layer.borderWidth = 0;
        
        self.screening_btn.layer.borderColor = RGB(238, 58, 68).CGColor;
    }
    else // 选中状态
    {
        [self.screening_btn setSelected:YES];
        
         [self.screening_btn setTitle:model.attributeName forState:(UIControlStateSelected)];
        
        self.screening_btn.layer.borderWidth = 1;
        
        self.screening_btn.layer.borderColor = RGB(238, 58, 68).CGColor;
    }
}

/**
 * @brief 筛选按钮的点击
 */
- (void)screening_btnClickAction:(UIButton *)sender{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(FilterTheClickOfThePropertiesButton:)]) {
        
        [self.delegate FilterTheClickOfThePropertiesButton:sender];
    }
}




@end
